#include <cstdio>

typedef long long ll;
int t;
ll a, b, c, d;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    ll mgcd = gcd(a, b);
    mgcd = gcd(mgcd, c);
    if (mgcd == 0) puts(d ? "NO" : "YES");
    else
      puts(d % mgcd ? "NO" : "YES");
  }
  return 0;
}